<template>
    <div>
        <a-modal
         v-model:visible="visible" 
         :title="formState.id?formState.view?'查看会议计划':'编辑会议计划':'新增会议计划'" 
         @ok="handleOk" 
         @cancel="visible = false"
         class="plan-add-edit-modal"
         :width="800"
         :footer="null"
        >
            <div v-if="visible">
                <a-form :form="form" layout="horizontal" class="add-edit-form">
                    <a-form-item label="会议标题">
                        <a-input
                        v-model:value="formState.fhybt"
                        placeholder="请输入会议标题"
                        v-decorator="[
                            'fhybt', { initialValue:formState.fhybt, rules: rules.fhybt}
                        ]"/>
                    </a-form-item>
                    <a-form-item label="会议摘要">
                        <a-input
                        v-model:value="formState.fhyzy"
                        placeholder="请输入会议摘要"
                        v-decorator="[
                            'fhyzy', { initialValue:formState.fhyzy, rules: rules.fhyzy}
                        ]"/>
                    </a-form-item>
                    <a-form-item label="会议地点" class="flex-1-box">
                        <a-input
                        v-model:value="formState.fhydd"
                        placeholder="请输入会议地点"
                        v-decorator="[
                            'fhydd', { initialValue:formState.fhydd, rules: rules.fhydd}
                        ]"/>
                    </a-form-item>
                    <a-form-item label="会议类型">
                        <a-select
                            ref="select"
                            placeholder="请选择设备类型"
                            v-model:value="formState.fhylx"
                            v-decorator="[
                                'fhylx', { initialValue:formState.fhylx, rules: rules.fhylx}
                            ]"
                            >
                            <a-select-option value="支部党员大会">支部党员大会</a-select-option>
                            <a-select-option value="支委会">支委会</a-select-option>
                            <a-select-option value="小组会">小组会</a-select-option>
                            <a-select-option value="党课">党课</a-select-option>
                            <a-select-option value="其他">其他</a-select-option>
                        </a-select>
                    </a-form-item>
                    <a-form-item label="会议记录人员" class="flex-1-box">
                        <div>
                            <a-button class="blue-btn" type="primary" @click="selectRecordPeople(false)">选择会议记录人员</a-button>
                        </div>
                        <a-textarea 
                            readOnly
                            placeholder="请输入会议记录人员"
                            v-model:value="formState.fhyjlryxm"
                            :autosize="{ minRows: 3, maxRows: 10000 }"
                            v-decorator="[
                                'fhyjlryxm', { initialValue:formState.fhyjlryxm, rules: rules.fhyjlryxm}
                            ]"
                        ></a-textarea>
                    </a-form-item>

                    <a-form-item label="首次会议开始时间">
                        <a-date-picker
                        format="YYYY-MM-DD HH:mm"
                        v-model:value="formState.fschykssj"
                        placeholder="请选择首次会议开始时间"
                        v-decorator="[
                            'fschykssj', { initialValue:formState.fschykssj, rules: rules.fschykssj}
                        ]"/>
                    </a-form-item>
                    <a-form-item label="会议间隔天数">
                        <a-input-number
                        style="width: 185px;"
                        :min="0"
                        :precision="0"
                        v-model:value="formState.fhyjgts"
                        placeholder="请输入会议间隔天数"
                        v-decorator="[
                            'fhyjgts', { initialValue:formState.fhyjgts, rules: rules.fhyjgts}
                        ]"/>
                    </a-form-item>
                    <a-form-item label="是否循环执行">
                        <a-select
                            ref="select"
                            placeholder="请选择是否循环执行"
                            v-model:value="formState.fsfxhzx"
                            v-decorator="[
                                'fsfxhzx', { initialValue:formState.fsfxhzx, rules: rules.fsfxhzx}
                            ]"
                            >
                            <a-select-option value="是">是</a-select-option>
                            <a-select-option value="否">否</a-select-option>
                        </a-select>
                    </a-form-item>
                    <a-form-item label="有效状态">
                        <a-select
                            ref="select"
                            placeholder="请选择有效状态"
                            v-model:value="formState.fyxzt"
                            v-decorator="[
                                'fyxzt', { initialValue:formState.fyxzt, rules: rules.fyxzt}
                            ]"
                            >
                            <a-select-option value="启动">启动</a-select-option>
                            <a-select-option value="暂停">暂停</a-select-option>
                        </a-select>
                    </a-form-item>
                </a-form>
            </div>
            <div style="
                display: flex; justify-content: flex-end;
                margin-top: 20px; width: 100%;
                background-color: #fff;">
                <a-button @click="visible = false">取消</a-button>
                <a-button v-if="!formState.view" style="margin: 0 20px;" class="blue-btn" type="primary" @click="handleOk(true)">保存</a-button>
                <a-button v-if="!formState.view" class="blue-btn" type="primary" @click="handleOk(false)">保存并关闭</a-button>
            </div>
            <personnelList ref="personnelListRef" @checkPersonnel="checkPersonnel" :modaObj="{place:'',oldId:formState.fhyjlry?formState.fhyjlry.split(','):[]}" />
        </a-modal>
    </div>
</template>
<script>
import compSelector from '@/components/compSelector/compSelector.vue'
import moment from 'moment'
import YchConstant from "@/api/YchConstant";
import blobType from '@/common/blobType'
import personnelList from '../../administrativeOffice-new/modal/personnelList.vue'
export default {
    components:{
        compSelector,
        personnelList,
    },
    props:{

    },
    data(){
        return{
            visible:false,
            formState:{},
            form: this.$form.createForm(this, { name: 'coordinated' }),
            rules:{
                fhybt: [{
                    required: true,
                    message: '请输入会议标题',
                    trigger: 'blur',
                }],
                fhydd: [{
                    required: true,
                    message: '请输入会议地点',
                    trigger: 'blur',
                }],
                fhylx: [{
                    required: true,
                    message: '请选择会议类型',
                    trigger: 'blur',
                }],
                fhyzy: [{
                    required: true,
                    message: '请输入会议摘要',
                    trigger: 'blur',
                }],
                fhyjlryxm: [{
                    required: true,
                    message: '请输入会议记录人员',
                    trigger: 'blur',
                }],
                fschykssj: [{
                    type:'object',
                    required: true,
                    message: '请选择首次会议开始时间',
                    trigger: 'blur',
                }],
                fhyjgts: [{
                    type:'number',
                    required: true,
                    message: '请输入会议间隔天数',
                    trigger: 'blur',
                }],
                fsfxhzx: [{
                    required: true,
                    message: '请选择是否循环执行',
                    trigger: 'blur',
                }],
                fyxzt: [{
                    required: true,
                    message: '请选择有效状态',
                    trigger: 'blur',
                }],
            },
            materialUnitList:[],
            uploadLoading:false,
            fjxxList:[],
            
        }
    },
    watch:{

    },
    mounted(){
    },
    methods:{
        getData(val){
            //console.log(val)
            this.formState = {}
            this.formState = val
            this.formState.fschykssj = val.fschykssj?moment(val.fschykssj):''
            
        },
        selectRecordPeople(){
            this.$refs.personnelListRef.personnelListVisible = true
            this.$refs.personnelListRef.getData({place:'',oldId:this.formState.fhyjlry?this.formState.fhyjlry.split(','):[]})
        },
        checkPersonnel(val,list,list2){
            this.formState.fhyjlry = list.length?list.join(','):''
            this.formState.fhyjlryxm = list2.length?list2.join('/'):''
            this.form.setFieldsValue({
                fhyjlryxm:list2.length?list2.join('/'):''
            });
        },
        handleOk(val){
            this.form.validateFields((err, values) => {
                if (!err) {
                    if(this.formState.id){
                        this.$emit('editItem',{...this.formState,...values,fschykssj:moment(this.formState.fschykssj).format('YYYY-MM-DD HH:mm')},val)
                    }else{
                        this.$emit('addItem',{...this.formState,...values,fschykssj:moment(this.formState.fschykssj).format('YYYY-MM-DD HH:mm')},val)
                    }
                    
                }
            })
        },
    }
}
</script>
<style lang="less">
.plan-add-edit-modal{
    .add-edit-form{
        display: flex;
        flex-wrap: wrap;
        .ant-form-item{
            display: flex;
        }
        .ant-form-item-label{
            width: 135px;
        }
        .ant-form-item-control-wrapper{
            width: 180px;
        }
        .flex-1-box{
            width: 100%;
            .ant-form-item-control-wrapper{
                flex: 1;
            }
        }
    }
}
</style>